Skip to content

fix(server): older history no longer reads every attempt row to find steered ones - #41620

Merged
juliusmarminge merged 1 commit into
mainfrom
factory/issue-41587
Nov 23, 2026
Merged

juliusmarminge merged 1 commit into
mainfrom
factory/issue-41587

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Opening the older history of a long thread was slow when the database was not cached in memory: finding the thread's few superseded (steered) attempts meant reading every attempt row of the thread. A new migration adds a partial index on superseded attempts, so that lookup reads only those rows. The first older-history page from a cold cache loads about 25% faster.

Fixes #41587

Reproduction on main

Commit: origin/main 7f0e736 (also on the leased Windows checkout). Scripts are the reporter's own (platform-repro.mjs, coordinator-data.mjs, compare-runtime.mjs, evict-fixture-linux.py), taken from the issue unchanged. Seeded on Linux with node platform-repro.mjs seed <main checkout> coordinator-matched.sqlite coordinator (Node 26.13.1, SQLite 3.54.1): 2,855 runs, 919 cancelled, 19,601 target items, 335 MB, the same fixture the report describes. The identical file (sha256 c82fdb7b…) was copied to a leased Windows Server 2025 machine (Xeon Platinum 8573C, 4 vCPU, NTFS) and run with node compare-runtime.mjs <main checkout> coordinator-matched.sqlite <out>.json 5 <warm-file|cold-file>. No extra load was added; sampled CPU was 36-63%. Both platforms gave the same VM steps as the report (superseded lookup 14,285, 0 rows; hidden-conversation lookup 70,577, 1 row). First-page times over 5 trials each: Linux warm median 150 ms (119-214); Linux cold with mincore-verified eviction median 1.66 s (1.56-1.86), superseded lookup 0.40-0.74 s; Windows warm median 140 ms (136-150), lookup about 19 ms; Windows cold with fresh robocopy /J copies, two batches of 5: 3.50, 2.58, 2.38, 2.26, 6.41 s and 2.83, 3.29, 3.19, 3.34, 2.53 s, median 2.9 s (2.26-6.41), 1 of 120 pages over 6 s. In those runs the superseded lookup took 0.57-2.30 s and openLocalTimeline 0.91-3.46 s. Later pages had a median of 90-133 ms everywhere. To confirm the share, the same fixture was given the reporter's partial index CREATE INDEX … ON orchestration_v2_projection_run_attempts(thread_id,run_id,root_node_id) WHERE status='superseded' and run cold on Windows: superseded lookup 9 VM steps, 0.80-0.98 ms; openLocalTimeline 0.33-0.42 s; first page median 1.88 s (1.76-1.98); 0 of 60 over budget. The reporter's 6-28 s first pages, seen with their host at 98-100% CPU, were not matched on this idle machine. The same cold-cache slow path, and its growth on Windows, was measured.

Evidence

Seed each commit's fresh database with the same synthetic coordinator history, then measure ten fresh-process trials on the same Windows Server 2025 host using fresh robocopy /J copies. Each trial loads the first older-history page, repeats it, and loads ten earlier pages.

Measurement Before After
Commit a369642c1c 8489cbd90c
First-page median 1,752.879 ms 1,276.736 ms
First-page min–max 1,736.663–1,779.114 ms 1,264.794–1,304.974 ms
Superseded lookup median 484.447 ms 0.733 ms
Superseded lookup VM steps 14,285 9
Pages over 6 seconds 0/120 0/120
Captured output Base measurements Head measurements

The first-page median improves by 476.144 ms (27.2%), exceeding both full observed ranges (42.451 ms and 40.180 ms). All 120 corresponding full-page hashes match. The production migration creates the covering partial index without manual indexing.

Before and after Windows measurements

Reproduction scripts and instructions · Measurement driver · Summary

Environment: Windows Server 2025, four vCPUs, Node 26.13.1, SQLite 3.54.1. CPU samples were 0–2%; no artificial load was added. This proves the server-path performance improvement, not the reporter's overloaded-host timeout.

Not shown:

  • The reporter's six-second budget failures at 98–100% CPU were not reproduced: this host was idle and neither commit exceeded six seconds.
  • Windows file-cache residency was not verified; fresh unbuffered robocopy /J copies used the reporter's preparation method.
  • HTTP, browser interaction, relay latency, and client cancellation were not measured; the capture measures the production ProjectionStore path.
  • The fixture has zero superseded attempts, so non-empty superseded-attempt hiding was not exercised.

Tests

  • vp test run src/persistence/reconcileV2PreviewMigration.test.ts src/persistence/Migrations.test.ts src/persistence/Sqlite.test.ts (apps/server): 3 files, 22 tests passed
  • vp run check:changed: knip, graphql, typecheck (3 packages) and tests (3 files) passed
  • Reporter's compare-runtime.mjs … 5 cold-file, before (main) and after (fix): Windows Server 2025, 2 batches of 5 each: first page median 1,656 ms before and 1,264 ms after, superseded lookup 14,285 VM steps before and 9 after; Linux, 5 trials each: median 1,492 ms before and 1,135 ms after; 0 pages over the 6 s budget
  • PR fix(server): older history no longer reads every attempt row to find steered ones #41620 CI on 8489cbd: all 8 required checks passed

Not in this change

  • The hidden-conversation candidate scan in openLocalTimeline still costs 70,577 VM steps (about 65 ms cold) and is the next largest part of the first page.
  • The run_interrupt_result and tail-run EXISTS subqueries filter on run_id and status = 'superseded' through the (run_id, attempt_ordinal) index; they are per-run and were not slow in these measurements.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

…steered ones

Opening a thread's older history looked up its superseded attempts with a
query that could only use the (thread_id, run_id) index, so it read every
attempt row of the thread. A partial index on superseded attempts makes it
read only those.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 732c712 · PR result: 8489cbd · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Migration 111 adds a partial index on superseded run attempts. The migration manifest registers it, and preview-upgrade tests expect it after migration 110.

Changes: Superseded Run Attempt Index

Layer / File(s) Summary
Create and register migration 111
apps/server/src/persistence/Migrations/111_SupersededRunAttemptIndex.ts, apps/server/src/persistence/Migrations.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
The migration creates the index if it does not exist. The manifest registers migration 111, and both preview-upgrade test expectations include it after migration 110.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: bil0000

Merge Risk: Minimal · up to 8489c

This adds a database index that speeds up loading older conversation history, and it does not change returned results. The migration can be applied safely more than once, and merge risk is minimal.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #41587 has two coding requirements. (1) Avoid scanning unrelated run-attempt rows to find superseded attempts. The head adds migration 111 (apps/server/src/persistence/Migrations/111_SupersededR… Provide the pending Evidence section, with before and after measurements on a busy Windows host that matches the issue conditions (fresh-copy first-page loads, 60 pages). Alternatively, provide a test or measurement showing returned pages a…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: older-history loading no longer scans every attempt row to find steered (superseded) attempts. It follows the conventional commit format and is specific to the fix. It…
Out of Scope Changes check Passed The changed files are Migrations.ts (import and manifest entry for migration 111), the new migration 111 file (one idempotent partial index on the run-attempts table), and reconcileV2PreviewMigration.…
Description check Passed The description is detailed and covers the problem (slow older-history loading on a cold cache, linked to issue #41587), the change (a partial index on superseded run attempts via migration 111), the …
Full details: Title check

Explanation

The title names the main change: older-history loading no longer scans every attempt row to find steered (superseded) attempts. It follows the conventional commit format and is specific to the fix. It is consistent with the added partial index on superseded run attempts and the linked issue.

Full details: Out of Scope Changes check

Explanation

The changed files are Migrations.ts (import and manifest entry for migration 111), the new migration 111 file (one idempotent partial index on the run-attempts table), and reconcileV2PreviewMigration.test.ts (expected migration list updated to include 111). Each change supports the index objective of #41587. The PR description also says the hidden-conversation candidate scan in openLocalTimeline is not changed. That scan reads thread or conversation rows, not run-attempt rows, so its omission does not conflict with the issue. No unrelated code change appears in the summary.

Full details: Description check

Explanation

The description is detailed and covers the problem (slow older-history loading on a cold cache, linked to issue #41587), the change (a partial index on superseded run attempts via migration 111), the scope (it cites the linked issue and the bug it reports), and verification (reproduction on Windows and Linux, benchmark tables, and the test commands with results). It does not use the template's section headings, but it addresses each required element. The title-style guidance is not applied here because the description is not a title. The author discloses limits: the reporter's six-second budget failures were not reproduced, and the hidden-conversation scan remains out of scope.

Full details: Linked Issues check

Explanation

Issue #41587 has two coding requirements. (1) Avoid scanning unrelated run-attempt rows to find superseded attempts. The head adds migration 111 (apps/server/src/persistence/Migrations/111_SupersededRunAttemptIndex.ts), a partial index on orchestration_v2_projection_run_attempts(thread_id, run_id, root_node_id) WHERE status = 'superseded', registered in Migrations.ts. This addresses the requirement in code. The author reports the superseded lookup fell from 14,285 VM steps to 9 on Windows and to under 1 ms, with matching returned pages. (2) First bounded history page completes within six seconds on the busy Windows host. The author reports a cold Windows median of 1,264 ms after the fix and 0 pages over 6 s. These runs used an idle machine with 36-63% CPU. The reporter's busy-host slow pages (6-28 s at 98-100% CPU) were not reproduced. The PR description's Evidence section is marked as pending. The busy-host budget requirement therefore has no verifying evidence. The page-preservation requirement is supported only by the author's report, not by a test in this diff.

Resolution

Provide the pending Evidence section, with before and after measurements on a busy Windows host that matches the issue conditions (fresh-copy first-page loads, 60 pages). Alternatively, provide a test or measurement showing returned pages are unchanged after the migration. The result must show whether first pages stay within six seconds under host load.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 732c712 and 8489cbd.

Files selected for processing: 3

  • apps/server/src/persistence/Migrations.ts
  • apps/server/src/persistence/Migrations/111_SupersededRunAttemptIndex.ts
  • apps/server/src/persistence/reconcileV2PreviewMigration.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@juliusmarminge
juliusmarminge merged commit 0fcfc17 into main Nov 23, 2026
39 checks passed
@juliusmarminge
juliusmarminge deleted the factory/issue-41587 branch November 23, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Older-history pages exceed the 6 s client budget on a busy Windows host

1 participant